package com.sunday.haowushop.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sunday.common.widgets.MarqueeView;
import com.sunday.common.widgets.banner.ConvenientBanner;
import com.sunday.haowushop.R;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by 刘涛 on 2017/4/12.
 */

public class IndexTodayAdapter extends RecyclerView.Adapter {


    private Context mContext;
    private final static int TYPE_HEAD = 0;
    private final static int TYPE_TABS = 1;
    private final static int TYPE_LIST1 = 2;
    private final static int TYPE_LIST2 = 3;

    public IndexTodayAdapter(Context context) {
        mContext = context;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_HEAD:
                View view = LayoutInflater.from(mContext).inflate(R.layout.layout_type_head, null);
                return new HeadHolder(view);
            case TYPE_TABS:
                view = LayoutInflater.from(mContext).inflate(R.layout.layout_type_tabs, null);
                return new TabsHolder(view);
            case TYPE_LIST1:
                view = LayoutInflater.from(mContext).inflate(R.layout.layout_product__brand_item, null);
                return new ListHolder1(view);
            case TYPE_LIST2:
                view = LayoutInflater.from(mContext).inflate(R.layout.layout_product_item, null);
                return new ListHolder2(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position == 1) {
            TabsHolder tabsHolder = (TabsHolder) holder;

        }
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_HEAD;
        } else if (position == 1) {
            return TYPE_TABS;
        } else if (position == 2) {
            return TYPE_LIST1;
        } else {
            return TYPE_LIST2;
        }
    }

    @Override
    public int getItemCount() {
        return 10;
    }

    class HeadHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.banner)
        ConvenientBanner banner;
        @Bind(R.id.marquee_view)
        MarqueeView marqueeView;

        public HeadHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class TabsHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tabs_list)
        RecyclerView recyclerView;

        public TabsHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class ListHolder1 extends RecyclerView.ViewHolder {

        @Bind(R.id.main_img)
        ImageView mainImg;
        @Bind(R.id.brand_img)
        ImageView brandImg;
        @Bind(R.id.brand_title)
        TextView brandTitle;
        @Bind(R.id.brand_star)
        TextView brandStar;
        @Bind(R.id.btn_share)
        ImageView btnShare;
        @Bind(R.id.btn_add_product)
        ImageView btnAddProduct;
        @Bind(R.id.total_layout)
        RelativeLayout totalLayout;

        public ListHolder1(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class ListHolder2 extends RecyclerView.ViewHolder {
        @Bind(R.id.main_img)
        ImageView mainImg;
        @Bind(R.id.product_title)
        TextView productTitle;
        @Bind(R.id.price_now)
        TextView priceNow;
        @Bind(R.id.price_old)
        TextView priceOld;
        @Bind(R.id.store_num)
        TextView storeNum;
        @Bind(R.id.btn_share)
        ImageView btnShare;
        @Bind(R.id.btn_add_product)
        ImageView btnAddProduct;
        @Bind(R.id.btn_check_material)
        ImageView btnCheckMaterial;
        @Bind(R.id.total_layout)
        RelativeLayout totalLayout;

        public ListHolder2(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
